package com.gz.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
 
    @Override
    protected void configure(HttpSecurity http) throws Exception {
        /** swagger过滤资源路径 */
//        String [] urls={
//            "/doc.html",
//            "/**/*.js",
//            "/**/*.css",
//            "/swagger-resources",
//            "/v2/api-docs",
//            "/admins/login"
//        };
        /** post请求解除403 */
        http.csrf().disable();
        http
            .authorizeRequests()
            /** 给swagger资源路径放行，但是动态接口不能通行 */
//            .antMatchers(urls).permitAll()
            /** 所有路径能通行 */
            .antMatchers("/**").permitAll()
//            .antMatchers("/**/**").permitAll()
            .antMatchers("/user/**").hasAnyRole("ADMIN", "USER")
            .anyRequest().authenticated()
            .and()
            .formLogin()
                .loginPage("/login")
                .permitAll()
            .and()
            .logout()
                .permitAll()
            ;
    }

//    @Override
//    public void configure(WebSecurity web){
//        web.ignoring().antMatchers(HttpMethod.GET,"/**doc.html","/**doc.html**","queryById");
//    }
}